import 'package:bitcatflutter/page/home_skeleton/skeleton_home.dart';
import 'package:bitcatflutter/page/home_skeleton/skeleton_mine.dart';
import 'package:bitcatflutter/page/home_skeleton/skeleton_order.dart';
import 'package:flutter/material.dart';

//首页骨架
class HomeSkeletonPage extends StatefulWidget {
  const HomeSkeletonPage({super.key});

  @override
  State<HomeSkeletonPage> createState() => _HomeSkeletonPageState();
}

class _HomeSkeletonPageState extends State<HomeSkeletonPage> {

  var pageController = PageController();

  var currentIndex = 0;

  var pageList = [
     SkeletonHome(),
    const SkeletonOrder(),
    const SkeletonMine()
  ];



  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).colorScheme.inversePrimary,
        title: const Text('首页骨架'),
        leading: const Icon(Icons.menu),
        actions: [
          IconButton(onPressed: (){}, icon: const Icon(Icons.search)),
          IconButton(onPressed: (){}, icon: const Icon(Icons.more_horiz)),
        ],
      ),
      body: PageView(
        controller: pageController,
        onPageChanged: (index)=>setState(() {
          currentIndex = index;
        }),
        children: pageList,
      ),
      bottomNavigationBar: BottomNavigationBar(items: _buildBottomItems(),currentIndex: currentIndex,onTap: (index){
        setState(() {
          currentIndex = index;
          pageController.jumpToPage(currentIndex);
        });
      },),
    );
  }

  List<BottomNavigationBarItem> _buildBottomItems(){
    return [
      _buildBottomItem(Icons.home, "首页"),
      _buildBottomItem(Icons.list, "订单"),
      _buildBottomItem(Icons.person, "我的"),
    ];
  }

  _buildBottomItem(IconData icon,String text) {
    return BottomNavigationBarItem(icon: Icon(icon),label: text);
  }
}
